package vip.xiaonuo.invoice.core.factory;

import vip.xiaonuo.common.exception.CommonException;
import vip.xiaonuo.invoice.core.adapter.InvoicePlatformAdapter;
import vip.xiaonuo.invoice.core.adapter.impl.NuonuoInvoiceAdapter;
import vip.xiaonuo.invoice.core.adapter.impl.ShuZuInvoiceAdapter;
import vip.xiaonuo.invoice.core.enums.invoice.InvoicePlatformEnum;
import vip.xiaonuo.invoice.core.exception.InvoiceException;

/**
 * 发票平台适配器工厂
 *
 * @author AI Assistant
 */
public class InvoicePlatformAdapterFactory {

    /**
     * 获取发票平台适配器
     *
     * @param platformCode 平台编码
     * @return 发票平台适配器
     */
    public static InvoicePlatformAdapter getAdapter(String platformCode) {
        InvoicePlatformEnum platform = InvoicePlatformEnum.getByCode(platformCode);
        if (platform == null) {
            throw new CommonException("不支持的发票平台：" + platformCode);
        }
        return getAdapterByEnum(platform);
    }

    /**
     * 获取发票平台适配器（基于枚举）
     *
     * @param platform 发票平台枚举
     * @return 发票平台适配器
     */
    public static InvoicePlatformAdapter getAdapterByEnum(InvoicePlatformEnum platform) {
        if (platform == null) {
            throw new InvoiceException("不支持的发票平台");
        }

        switch (platform) {
            case SHUZU:
                return new ShuZuInvoiceAdapter();
            case NUONUO:
                return new NuonuoInvoiceAdapter();
            default:
                throw new CommonException("不支持的发票平台：" + platform);
        }
    }
}
